package com.zg.common.core.util;

import java.util.Calendar;
import java.util.Date;

/**
 * DESCRIPTION
 *
 * @author zhanfeng.liang
 * @since 2025-07-14
 */

public class DateUtil {

    public static Date getToEndOfDay(Date date) {
        if (date == null) {
            return null;
        }

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 0); // 清除毫秒

        return calendar.getTime();
    }

    /**
     * 获取指定日期的起始时间（00:00:00）
     */
    public static  Date getBeginOfDay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // 重置时分秒为0
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }
}
